﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils.UIPermission;
using Pap.Web.Modules.Administration.ViewModel;
using Pap.Data;
using Coolite.Ext.Web;

namespace Pap.Web.Modules.Administration.Views
{
    public partial class ImagesSearch : Pap.Web.Utils.BasePage<ImagesSearchViewModel>, IPermittedPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && !Ext.IsAjaxRequest)
            {
                sImageTypes.DataSource = this.ViewModel.GetImageTypes();
                sImageTypes.DataBind();
                //this.ImageView.Listeners.Click.Handler = string.Concat(this.ClientID, "_class.ShowPreview();");
                //this.ImageView.Listeners.SelectionChange.Buffer = 100;
            }

        }

        /// <summary>
        /// Dvs the image selection change.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Coolite.Ext.Web.AjaxEventArgs"/> instance containing the event data.</param>
        protected void DvImageSelectionChange(object sender, AjaxEventArgs e)
        {
            var imageId = e.ExtraParams["ImageId"].ToString();
            Image1.ImageUrl = "/image.route?imageId=" + imageId;
            Image1.Show();
            
        }


        protected void BtnSearchClick(object sender, AjaxEventArgs e)
        {
            if (cmbType.SelectedIndex != -1)
                sImages.DataSource = this.ViewModel.FindImages(txtPhotoLabels.Text, cmbType.SelectedItem.Value.ToGuid());
            else
                sImages.DataSource = this.ViewModel.FindImages(txtPhotoLabels.Text, null);
            sImages.DataBind();
        }

        public string PermissionName 
        {
            get { return "ImagesSearch"; }
        }

    }
}